//
//  ViewController2.m
//  20202
//
//  Created by student on 16/3/16.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController2.h"
#import "ViewController.h"
@interface ViewController2 ()<viewControllerDelegate>
@property (nonatomic,strong)NSUserDefaults *d;
@end

@implementation ViewController2

- (IBAction)view:(UIControl *)sender {
    
    [self.textFieldR resignFirstResponder];
    [self.textFieldG resignFirstResponder];
    [self.textFieldB resignFirstResponder];
    
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.d = [NSUserDefaults standardUserDefaults];
    
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)changedColor
{
    [self.background setBackgroundColor: [UIColor colorWithRed:[self.textFieldR.text floatValue]/255.0 green:[self.textFieldG.text floatValue]/255.0 blue:[self.textFieldB.text floatValue]/255.0 alpha:150/255.0]];
    [self.d setObject:self.textFieldR.text forKey:@"Red"];
    [self.d setObject:self.textFieldG.text forKey:@"Green"];
    [self.d setObject:self.textFieldB.text forKey:@"Blue"];

}
- (IBAction)SliderR:(UISlider *)sender
{
    int value = sender.value;
    self.textFieldR.text = [NSString stringWithFormat:@"%i",value];
    [self changedColor];
}

- (IBAction)SliderG:(UISlider *)sender
{
    int value = sender.value;
    self.textFieldG.text = [NSString stringWithFormat:@"%i",value];
    [self changedColor];
}

- (IBAction)SliderB:(UISlider *)sender
{
    int value = sender.value;
    self.textFieldB.text = [NSString stringWithFormat:@"%i",value];
    [self changedColor];
}

- (IBAction)textFieldR:(UITextField *)sender
{
    int value = [self.textFieldR.text floatValue];
    [self.sliderRed setValue:value];
    [self changedColor];
    
}

- (IBAction)textFieldG:(UITextField *)sender
{
    int value = [self.textFieldG.text floatValue];
    [self.SliderGreen setValue:value];
    [self changedColor];
    
}

- (IBAction)textFieldB:(UITextField *)sender
{
    int value = [self.textFieldB.text floatValue];
    [self.SliderBlue setValue:value];
    [self changedColor];
    
}
- (IBAction)Cancer:(id)sender
{
    [self dismissViewControllerAnimated:YES  completion:nil];
}




@end
